package com.functest.orm

import com.functest.framework.BaseFunctionalTest
import org.testng.annotations.DataProvider
import org.testng.annotations.Test

/**
 * Created with IntelliJ IDEA.
 * User: KovalevAS
 * Date: 10.09.13
 * Time: 18:58
 * To change this template use File | Settings | File Templates.
 */
class JoinTypeTest extends BaseFunctionalTest{

    static List<JoinType> acceptableJoinTypes = [JoinType.INNER, JoinType.LEFT_OUTER, JoinType.RIGHT_OUTER]

    @DataProvider
    Object[][] getSqlPositiveData(){
        [
                [JoinType.INNER, "inner"],
                [JoinType.LEFT_OUTER, "left outer"],
                [JoinType.RIGHT_OUTER, "right outer"]
        ]
    }

    @Test(dataProvider = 'getSqlPositiveData')
    void getSqlPositiveTest(JoinType joinType, String expected){
        assert joinType.getSql() == expected
    }

    @DataProvider
    Object[][] getSqlNegativeData(){
        List otherJoinTypes = JoinType.values() - acceptableJoinTypes
        List res = []
        otherJoinTypes.each { JoinType joinType ->
            res << [joinType]
        }
    }

    @Test(dataProvider = 'getSqlNegativeData')
    void getSqlNegativeTest(JoinType joinType){
        try {
            joinType.getSql()
        }
        catch (RuntimeException ignored){
            assert true
        }
        catch (Exception ex){
            assert false, "Unexpected exception: $ex"
        }
    }

}
